﻿#include <QCoreApplication>

#include <iostream>
#include <string>
#include <zmq.hpp>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    std::cout << "ZeroMQ Version-> major: " << std::get<0>(zmq::version()) << " "
                << "minor: " << std::get<1>(zmq::version()) << " "
                << "patch: " << std::get<2>(zmq::version()) << " "
                << std::endl;

    // Prepare our context and socket
    zmq::context_t context(1);
    zmq::socket_t socket(context, zmq::socket_type::req);

    std::cout << "Connecting to hello world server…" << std::endl;
    socket.connect("tcp://localhost:5555");

    // Do 10 requests, waiting each time for a response
    for (int request_nbr = 0; request_nbr != 10; request_nbr++) {
        zmq::message_t request(5);
        memcpy(request.data(), "Hello", 5);
        std::cout << "Sending Hello " << request_nbr << "…" << std::endl;
        socket.send(request, zmq::send_flags::none);

        // Get the reply.
        zmq::message_t reply;
        socket.recv(reply, zmq::recv_flags::none);
        std::cout << "Received World " << request_nbr << std::endl;
    }

    return a.exec();
}
